home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / cview.jar / content / cview / cview-static.js < prev    next >
Encoding:
JavaScript  |  2004-04-18  |  6.9 KB  |  263 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Robert Ginda, rginda@netscape.com, original author
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. /*
  41.  * This file contains "static" functions for cview.  In this case static just
  42.  * means not-an-event-handler.  If you can come up with a better name, let
  43.  * me know.  The main code of cview is divided between this file and
  44.  * cview-handlers.js
  45.  */
  46.  
  47. var cview = new Object();
  48. /*
  49.  * instead of creating a slew of global variables, all app-wide values are
  50.  * stored on this cview object.
  51.  */
  52.  
  53. /* number of items to process per refresh step */
  54. cview.REFRESH_ITEMS_PER_CYCLE = 30;
  55. /* number of milliseconds to wait between refresh steps */
  56. cview.REFRESH_CYCLE_DELAY = 200;
  57.  
  58. cview.componentMode = "all";
  59. cview.interfaceMode = "all";
  60.  
  61. /*
  62.  * hide/show entries in the components list based on the componentMode and
  63.  * componentFilter properties of the cview object.
  64.  */
  65. function filterComponents()
  66. {
  67.     function filterAll (rec)
  68.     {
  69.         if (rec.isHidden)
  70.             rec.unHide();
  71.         cview.visibleComponents++;
  72.     }
  73.         
  74.     function filterContains (rec)
  75.     {
  76.         if (rec.name.search(cview.componentFilter) != -1)
  77.         {
  78.             if (rec.isHidden)
  79.                 rec.unHide();
  80.             cview.visibleComponents++;
  81.         }
  82.         else
  83.         {
  84.             if (!rec.isHidden)
  85.                 rec.hide();
  86.         }
  87.     }
  88.         
  89.     function filterStarts (rec)
  90.     {
  91.         if (rec.name.search(cview.componentFilter) == 0)
  92.         {
  93.             if (rec.isHidden)
  94.                 rec.unHide();
  95.             cview.visibleComponents++;
  96.         }
  97.         else
  98.         {
  99.             if (!rec.isHidden)
  100.                 rec.hide();
  101.         }
  102.     }        
  103.             
  104.     var cmps  = cview.componentView.childData.childData;
  105.     var count = cmps.length;
  106.  
  107.     cview.visibleComponents = 0;
  108.  
  109.     switch (cview.componentMode)
  110.     {
  111.         case "all":
  112.             filterFunction = filterAll;
  113.             break;
  114.  
  115.         case "contains":
  116.             filterFunction = filterContains;
  117.             break;
  118.  
  119.         case "starts-with":
  120.             filterFunction = filterStarts;
  121.             break;
  122.     }
  123.         
  124.  
  125.     for (var i = 0; i < count; ++i)
  126.         filterFunction (cmps[i]);
  127.     
  128.     refreshLabels();
  129.     
  130. }
  131.  
  132. /*
  133.  * Same as filterComponents() except it works on the interface list
  134.  */
  135. function filterInterfaces()
  136. {
  137.     function filterAll (rec)
  138.     {
  139.         if (rec.isHidden)
  140.             rec.unHide();
  141.         cview.visibleInterfaces++;
  142.     }
  143.         
  144.     function filterContains (rec)
  145.     {
  146.         if (rec.name.search(cview.interfaceFilter) != -1)
  147.         {
  148.             if (rec.isHidden)
  149.                 rec.unHide();
  150.             cview.visibleInterfaces++;
  151.         }
  152.         else
  153.         {
  154.             if (!rec.isHidden)
  155.                 rec.hide();
  156.         }
  157.     }
  158.         
  159.     function filterStarts (rec)
  160.     {
  161.         if (rec.name.search(cview.interfaceFilter) == 0)
  162.         {
  163.             if (rec.isHidden)
  164.                 rec.unHide();
  165.             cview.visibleInterfaces++;
  166.         }
  167.         else
  168.         {
  169.             if (!rec.isHidden)
  170.                 rec.hide();
  171.         }
  172.     }
  173.  
  174.     var ifcs  = cview.interfaceView.childData.childData;
  175.     var count = ifcs.length;
  176.  
  177.     cview.visibleInterfaces = 0;
  178.  
  179.     switch (cview.interfaceMode)
  180.     {
  181.         case "all":
  182.             filterFunction = filterAll;
  183.             break;
  184.  
  185.         case "contains":
  186.             filterFunction = filterContains;
  187.             break;
  188.  
  189.         case "starts-with":
  190.             filterFunction = filterStarts;
  191.             break;
  192.     }
  193.         
  194.  
  195.     for (var i = 0; i < count; ++i)
  196.         filterFunction (ifcs[i]);
  197.     
  198.     refreshLabels();    
  199.  
  200. }
  201.  
  202.  
  203. /*
  204.  * Update the list headings based on the componentMode and
  205.  * componentFilter properties of the cview object.
  206.  */
  207. function refreshLabels()
  208. {
  209.     var value = "";
  210.     
  211.     switch (cview.componentMode)
  212.     {
  213.         case "all":
  214.             value = "All components";
  215.             break;
  216.             
  217.         case "contains":
  218.             value = "Components containing '" + cview.componentFilter + "'";
  219.             break;
  220.  
  221.         case "starts-with":
  222.             value = "Components starting with '" + cview.componentFilter + "'";
  223.             break;
  224.  
  225.         default:
  226.             value = "Components?";
  227.             break;
  228.     }
  229.  
  230.     value += " (" + cview.visibleComponents + "/" + cview.totalComponents + ")";
  231.     document.getElementById("component-label").setAttribute ("value", value);
  232.     
  233.     switch (cview.interfaceMode)
  234.     {
  235.         case "all":
  236.             value = "All interfaces";
  237.             break;
  238.             
  239.         case "contains":
  240.             value = "Interfaces containing '" + cview.interfaceFilter + "'";
  241.             break;
  242.  
  243.         case "starts-with":
  244.             value = "Interfaces starting with '" + cview.interfaceFilter + "'";
  245.             break;
  246.  
  247.         case "implemented-by":
  248.             if (!cview.interfaceFilter)
  249.                 value = "Please select a component";
  250.             else
  251.                 value = "Interfaces implemented by '" +
  252.                     Components.classes[cview.interfaceFilter] + "'";
  253.             break;
  254.  
  255.         default:
  256.             value = "Interfaces?";
  257.             break;
  258.     }
  259.  
  260.     value += " (" + cview.visibleInterfaces + "/" + cview.totalInterfaces + ")";
  261.     document.getElementById("interface-label").setAttribute ("value", value);
  262. }
  263.